<%@ page language="java" contentType="text/html; charset=utf-8 " import="java.util.Date,java.text.*,domain.Community,domain.User,java.util.List"
    pageEncoding="utf-8"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <base href="<%=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/" %>"/>
    <meta charset="utf-8" />
	<title></title>
</head>

<script type="text/javascript">
	function beforeSubmit(){
		if(document.getElementById('newCommunityName').value==''){
			alert('社区名不能为空！');
			document.getElementById('newCommunityName').focus();
			return false;
		}
		if(document.getElementById('newCommunityInfo').value==''){
			alert('社区的详细地址不能为空！');
			document.getElementById('newCommunityInfo').focus();
			return false;
		}
	}
	function beforeSubmit1() {
		if(document.getElementById('updateCommunityInfo').value==''){
			alert('修改后的社区详细不能为空！');
			document.getElementById('updateCommunityInfo').focus();
			return false;
		}
	}
	function messageLoad(){
		var message = '<%=request.getAttribute("message") %>';
		if(message != 'null'){
			alert(message);
		}
	}
</script>

<style type="text/css">
	body{
	color: #555;
	background-color: rgba(0, 0, 0, 0.08);
	font-size: 80%;
		}
	.navigation{
		position: absolute;
		height: 100%;
		width: 20%;
		top: 0;
		left: 0;
		box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
		background: white;
	}
	.top{
		position: absolute;
		top: 0;
		left: 21%;
		height: 10%;
		width: 78%;
		box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
		background: white;
	}
	.main{
		position: absolute;
		top: 12%;
		left: 21%;
		width: 78%;
		height: 86%;
		box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
		background: white;
	}
	.logo{
		margin: auto;
		margin-top: 10%;
		background: url(img/logo.png);
		width: 60%;
		margin-bottom:10% ;
	}
	.click_box{
		text-align: center;
		border-top: black solid 1px;
		border-bottom: black solid 1px ;
		background: #199ED8;
		color: white;
		padding: 3%;
		font-size: 160%;
	}
	.unclick_box{
		text-align: center;
		border-top: black solid 1px;
		border-bottom: black solid 1px ;
		padding: 3%;
		font-size: 160%;
	}
	.unclick_box:hover{
		background: #199ED8;
		color: white;
	}
	.out_login:hover{
		color: #199ED8;
	}
	button{
		margin:10px;
		background: #199ED8;
		font-size: 100%;
		color: white;
		width: 100px;
		height: 30px;
		border: 0px;
		border-radius: 5px;
	}
	table{
		position: relative;
		top: 0;

		min-height: 25px;
		line-height: 25px;
		text-align: center;
		border-collapse: collapse;
		top: 0%;
		left: 5%;
		width: 90%;
		height: 75%;
	}
	td{
		height: 6%;
	}
	th{
		background: #199ED8;
		color: white;
	}
	table tr:nth-child(odd){
		background: #F2F2F2;
	}
	#shadow{
		background: #000;
		filter: alpha(opacity=50); /* IE的透明度 */
		opacity: 0.9; /* 透明度 */
		display: none;
		position: fixed;
		top: 0px;
		left: 0px;
		width: 100%;
		height: 100%;
		z-index: 100; /* 此处的图层要大于页面 */
		display: none;
	}
	.box{
		border: 1px solid black;
		width: 30%;
		height: 40%;
		position: fixed;
		top: 30%;
		left: 35%;
		opacity: 1;
		margin: 0 auto;
		text-align: center;
		background: white;
		border-radius: 5px;
		z-index: 101;
		box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
	}
	.title{
		width: 100%;
		background: #F2F2F2;
		height: 15%;
		border-top-left-radius: 5px;
		border-top-right-radius: 5px;
		box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
		border-bottom: 0.5px antiquewhite solid;
	}
	input{
		border: 1px solid #ccc;
		padding: 7px 0px;
		border-radius: 3px;
		padding-left:5px;
		-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
		box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
		-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
		-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
		transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s
	}
	input:focus{
		border-color: #66afe9;
		outline: 0;
		-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);
		box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)
	}
</style>

<%
	User user=new User();
	if(session.getAttribute("adminloginflag")==null){
%>
<script type="text/javascript">
	window.location.href="admin/login.jsp";
</script>
<%  }else{
	user=(User)session.getAttribute("adminloginflag");
%>

<body onload="messageLoad()">
	<div class="navigation">
		<center><img src="image/logo.png" class="logo"  /></center>
		<% if(user.getUsername().equals("admin")){ %><div class="unclick_box" onclick="userManage()">用户配置</div> <% } %>
		<% if(user.getCommunity_power()==1 ){%><div class="click_box" onclick="Community()">社区配置</div> <% } %>
		<% if(user.getRoom_power()==1 ){%><div class="unclick_box" onclick="Room()">住房审核</div> <% } %>
		<% if(user.getView_power()!=null&&!user.getView_power().equals("null") ){%><div class="unclick_box" onclick="info()">人员信息</div> <% } %>
	</div>

	<div class="top">
		<div style="float: left;margin:2%;font-size: 160%;">
			<%=new SimpleDateFormat("yyyy-MM-dd E").format(new Date())  %>
		</div>
		<div style="float: right;margin:2%;font-size: 160%;">
			<span> <img src="image/u954.svg"/></span>
			<span style="margin-right: 20px;"><%=user.getUsername() %></span>
			<span class="out_login" onclick="AdminOutlogin()">退出</span>
		</div>
	</div>

	<div class="main">
		<div style="float: right;margin-right: 5%;margin-top: 3%;">
			<button onclick="showAddCommunity()">新增社区</button>
		</div>
		<table border="1">
			<tr>
			<th width="20%">社区id</th>
			<th width="25%">社区名</th>
			<th width="35%">社区信息</th>
			<th width="20%">操作</th>
			</tr>
			<% for(int i=0;i<15;i++){ %>
			<tr>
			<% List<Community> list=(List)request.getAttribute("list");
			   if(i<list.size()){
			%>
			<td><%=list.get(i).getCommunity_id() %></td>
			<td><%=list.get(i).getCommunity_name() %></td>
			<td><%=list.get(i).getCommunity_info() %></td>
			<td>
				<a onclick= "show2(<%=list.get(i).getCommunity_id()%>,'<%=list.get(i).getCommunity_name()%>')" >修改</a>
				<a onclick= "show3(<%=list.get(i).getCommunity_id()%>,'<%=list.get(i).getCommunity_name()%>','<%=list.get(i).getCommunity_info()%>')">删除</a>
			</td>
			</tr><%} else{%>
			<td> </td><td> </td><td> </td><td> </td><%}}%>
		</table>
		<div style="float: right;margin-right: 5%;margin-top: 1%;">
			<c:choose>
						<c:when test="${page.hasPrePage}">
							<a href="CommunityInfo?method=list&currentPage=1">首页</a> |
					<a href="CommunityInfo?method=list&currentPage=${page.currentPage -1 }">上一页</a>
						</c:when>
						<c:otherwise>

						</c:otherwise>
					</c:choose>
				   当前为第${page.currentPage}页,共${page.totalPage}页
			<c:choose>
						<c:when test="${page.hasNextPage}">
							<a href="CommunityInfo?method=list&currentPage=${page.currentPage + 1 }">下一页</a> |
					<a href="CommunityInfo?method=list&currentPage=${page.totalPage }">尾页</a>
						</c:when>
						<c:otherwise>

						</c:otherwise>
					</c:choose>
		</div>
	</div>

	<div id="shadow">
		<div class="box" id="CreatCommunity">
			<div class="title">
				<span style="margin:5px;float: left;font-weight: 600;">创建新社区</span><span style="float: right;margin: 10px;font-weight: 800;" onclick="hidden2()">X</span>
			</div><br /><br />
			<form action="adminCreateCommunity" method="post" onsubmit="return beforeSubmit(this)">
				<input type="text" id="newCommunityName" name="newCommunityName" placeholder="社区名" onblur=""/><br />
				<span id="info"></span><br /><br />
				<input type="text" id="newCommunityInfo" name="newCommunityInfo" placeholder="详细地址"/><br /><br />
				<button id="submit" type="submit">确认创建</button>
			</form>
		</div>
		<div class="box" id="updateCommunity">
			<div class="title">
				<span style="margin:5px;float: left;font-weight: 600;">修改社区信息</span><span style="float: right;margin: 10px;font-weight: 800;" onclick="hidden2()">X</span>
			</div><br /><br />
			<form id="updateCommunityform" method="post" onsubmit="return beforeSubmit1(this)">
				<div style="width:60%;text-align: left;margin: auto;">
					<span id="Community_name" name="Community_name"></span><br /><br />
					<span id="Community_id" name="Community_id"></span><br /><br />
					<input type="text" id="updateCommunityInfo" name="updateCommunity" placeholder="修改社区信息"/><br /><br />
					<button type="submit" >确认修改</button>
				</div>
			</form>
		</div>
		<div class="box" id="deleteCommunity">
			<div class="title">
				<span style="margin:5px;float: left;font-weight: 600;">删除社区信息</span><span style="float: right;margin: 10px;font-weight: 800;" onclick="hidden2()">X</span>
			</div><br /><br />
			<form id="deleteCommunityform" method="post">
				<div style="width:60%;text-align: left;margin: auto;">
					<span id="Community_Did" name="Community_Did"></span><br /><br />
					<span id="Community_Dname" name="Community_Dname"></span><br /><br />
					<span id="Community_Dinfo" name="Community_Dinfo"></span><br /><br />
					<button type="submit" >确认删除</button>
				</div>
			</form>
		</div>
	</div>
</body>
    	<% } %>

	<script type="text/javascript">
			function AdminOutlogin(){
				window.location.href="AdminOutLogin";
			}
			function userManage(){
				window.location.href="UserInfo";
			}
			function Community(){
				window.location.href="CommunityInfo";
			 }
			function Room(){
				window.location.href="RoomInfo";
			 }
			function info(){
				window.location.href="Info";
			 }
			function showAddCommunity(){
				document.getElementById("shadow").style.display="block";
				document.getElementById("CreatCommunity").style.display="block";
				document.getElementById("updateCommunity").style.display="none";
				document.getElementById("deleteCommunity").style.display="none";

			}
			function hidden2(){
				document.getElementById("shadow").style.display="none";
				document.getElementById("CreatCommunity").style.display="none";
				document.getElementById("updateCommunity").style.display="none";
				document.getElementById("deleteCommunity").style.display="none";
			}
			function show2(communityId,communityName){
				document.getElementById("shadow").style.display="block";
				document.getElementById("updateCommunity").style.display="block";
				document.getElementById("CreatCommunity").style.display="none";
				document.getElementById("deleteCommunity").style.display="none";
				document.getElementById("Community_name").innerHTML="社区名："+communityName;
				document.getElementById("Community_id").innerHTML="社区id："+communityId;
				document.getElementById("updateCommunityform").action="adminUpdataCommunity?Community_id="+communityId;
			}
			function show3(communityId,communityName,communityInfo){
				document.getElementById("shadow").style.display="block";
				document.getElementById("Community_Did").innerHTML="社区id："+communityId;
				document.getElementById("Community_Dname").innerHTML="社区名："+communityName;
				document.getElementById("Community_Dinfo").innerHTML="社区详细地址："+communityInfo;
				document.getElementById("deleteCommunity").style.display="block";
				document.getElementById("updateCommunity").style.display="none";
				document.getElementById("CreatCommunity").style.display="none";
				document.getElementById("deleteCommunityform").action="deleteCommunity?Community_id="+communityId;
			}
	</script>

</html>